﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using KJFramework.ServiceModel.Bussiness.Default.Proxy;
using KJFramework.ServiceModel.Elements;
using KJFramework.ServiceModel.Objects;
using KJFramework.ServiceModel.Proxy;
using KJFramework.Timer;
using ServerTest;
using ServerTest.Contract;

namespace ClientTest
{
    class Program
    {
        private static int count = 0;
        private static int callbackcount = 0;
        static void Main(string[] args)
        {
            Program program = new Program();
            program.Test1();
            Console.WriteLine("Finished.");
            Console.ReadLine();
        }

        public void Test1()
        {
            LightTimer.NewTimer(1000, -1).Start(delegate
            {
                Console.Title = String.Format("Callbacks {0}", callbackcount);
            }, null);
            Console.WriteLine("开始执行......");
            IClientProxy<IHelloWorld> instance0 = new DefaultClientProxy<IHelloWorld>(new TcpBinding("tcp://10.10.36.168:9999/Test"));
            InObject inObject = new InObject { Inf1 = 1, Info2 = DateTime.Now, Info = "Info", Info3 = new[] { "1", "2" }, Info4 = new[] { 3, 4 } };
            CodeTimer.Initialize();
            CodeTimer.Time("Client Performane Test: 1000000", 1000000, delegate
            {
                instance0.Channel.TestIntellectObjectAsync(inObject, delegate(IAsyncCallResult callResult)
                {
                    if (callResult.IsSuccess) Interlocked.Increment(ref callbackcount);
                    else if (!callResult.IsSuccess && callResult.LastError != null) throw callResult.LastError;
                });
                count += 1;
            });
            Console.ReadLine();
        }
    }
}
